{{ template "layout/header" .}}
<style>
    .tagactive {
        color: #9B703F;
        font-weight: bold;
        background-color: papayawhip;
    }
</style>

{{/*获取的参数:{{.fid}}
<br>
第几页:{{.page}}--{{.sessions.Userid}}
<br>
登录用户:{{.sessions.Username}}
<br>
是管理员身份:{{.sessions}}
<br>
{{.foruminfoxx}}---*/}}


<main id="body">
    <div class="container">
        <div class="row">
            <div class="col-lg-9 main">
                {{ template "layout/emailcheck" .}}

                <ol class="breadcrumb d-none d-md-flex">
                    <li class="breadcrumb-item"><a href="/index.html"><i class="icon-home" aria-hidden="true"></i></a></li>
                    <li class="breadcrumb-item active"><a href="/forum/{{.foruminfoxx.ID}}/list.html">{{.foruminfoxx.Name}}</a></li>

                </ol>

                {{if .tags}}
                <div style="padding: 0.8rem 0.8rem;" class="card" id="taglist">
                    {{range .tags}}
                    <div style="padding: 0.3rem 0">
                        <table>
                            <tbody>
                            <tr>
                                <td valign="top" style="white-space: nowrap"><span class="grey">{{.TagCate.Name}}：</span>
                                </td>
                                <td>
                                    <a onclick="pickTagThread(this, {{.ForumID}})" class="tagactive" style="padding-right: 0.3rem" href="#" rel="nofollow" tagid="0">全部</a>
                                    {{$fid := .ForumID}}
                                    {{range .TagCate.Tags}}
                                    <a onclick="pickTagThread(this, {{$fid}})"  href="#" rel="nofollow" tagid="{{.ID}}">{{.Name}}</a>
                                    {{end}}
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                    {{end}}
                </div>
                {{end}}

                <div class="card card-threadlist">
                    <div class="card-header">
                        <ul class="nav nav-tabs card-header-tabs">
                            <li class="nav-item">
                                <a class="nav-link active" href="/">最新</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link  " href="?index-0-1.htm">精华</a>
                            </li>
                        </ul>
                    </div>
                    <div class="card-body">
                        <ul id="forumthreadlist" class="list-unstyled threadlist mb-0">
                            {{$sesid := .sessions.Userid}}
                            {{$isadmin := .sessions.Isadmin}}

                            {{range .forum_top_thread_list}}
                                <li class="media thread tap  " data-href="/thread/{{.ThreadID}}/detail.html" data-tid="22">
                                    {{if eq $isadmin "1"}}
                                        <input type="checkbox" name="modtid" class="mt-3 mr-2" value="{{.ThreadID}}">
                                    {{end}}
                                    <a href="{{if eq .Thread.User.ID $sesid}} /my.html {{else}}/user/{{.Thread.User.ID}}/info.html{{end}}" tabindex="-1" class="ml-1 mt-1 mr-3">
                                        <img class="avatar-3" src="{{.Thread.User.Avatar}}">
                                    </a>
                                    <div class="media-body">
                                        <div class="subject break-all font-weight-bold">
                                            <i class="icon-top-{{.Thread.Top}}"></i>
                                            <a href="/thread/{{.ThreadID}}/detail.html">{{.Thread.Subject}}</a>
                                            {{if .Thread.FilesNum}}
                                                <i class="icon small filetype other"></i>
                                            {{end}}
                                        </div>
                                        <div class="d-flex justify-content-between small mt-1">
                                            <div>
                                                <span class="username text-grey mr-1 " uid="1">{{.Thread.User.Username}}</span>
                                                <span class="date text-grey">{{.Thread.CreatedAt.Unix | strtime}}</span>
                                            </div>
                                            <div class="text-muted small">
                                                <span class="ml-2"><i class="icon-eye"></i> {{.Thread.ViewsCnt}}</span>
                                                <span class="ml-2"><i class="icon-comment-o"></i> {{.Thread.PostsCnt}}</span>
                                            </div>
                                        </div>
                                    </div>
                                </li>
                            {{end}}

                            {{ range .threadList}}

                                <li class="media thread tap  " data-href="/thread/{{.ID}}/detail.html" data-tid="22">
                                    {{if eq $isadmin "1"}}
                                    <input type="checkbox" name="modtid" class="mt-3 mr-2" value="{{.ID}}">
                                    {{end}}
                                    <a href="{{if eq .User.ID $sesid}} /my.html {{else}}/user/{{.User.ID}}/info.html{{end}}" tabindex="-1" class="ml-1 mt-1 mr-3">
                                        <img class="avatar-3" src="{{.User.Avatar}}">
                                    </a>
                                    <div class="media-body">
                                        <div class="subject break-all font-weight-bold">
                                            <a href="/thread/{{.ID}}/detail.html">{{.Subject}}</a>
                                            {{if .FilesNum}}
                                                <i class="icon small filetype other"></i>
                                            {{end}}
                                        </div>
                                        <div class="d-flex justify-content-between small mt-1">
                                            <div>
                                                <span class="username text-grey mr-1 " uid="1">{{.User.Username}}</span>
                                                <span class="date text-grey">{{.CreatedAt.Unix | strtime}}</span>
                                            </div>
                                            <div class="text-muted small">
                                                <span class="ml-2"><i class="icon-eye"></i> {{.ViewsCnt}}</span>
                                                <span class="ml-2"><i class="icon-comment-o"></i> {{.PostsCnt}}</span>
                                            </div>
                                        </div>
                                    </div>
                                </li>
                            {{end}}
                        </ul>
                    </div>
                </div>

                {{ template "mod/thread_list_mod.inc" .}}

                <nav id="pagenation" class="my-3">
                    <ul class="pagination justify-content-center flex-wrap">
                        {{.pages | unescaped}}
                    </ul>
                </nav>
            </div>
            <div class="col-lg-3 d-none d-lg-block aside">
                {{ template "layout/addnewthread" .}}
                <div class="card card-forum-info">
                    <div class="card-body text-center">
                        <img class="logo-5 mb-2" src="{{.foruminfoxx.Icon}}">
                        <h5>{{.foruminfoxx.Name}}</h5>

                        <div class="text-left line-height-2">{{.foruminfoxx.Brief}}</div>

                    </div>
                    <div class="card-footer p-2">
                        <table class="w-100 small">
                            <tbody>
                                <tr align="center">
                                    <td>
                                        <span class="text-muted">主题数</span><br>
                                        <b>{{.foruminfoxx.ThreadsCnt}}</b>
                                    </td>
                                    <td>
                                        <span class="text-muted">今日贴子</span><br>
                                        <b>{{.foruminfoxx.TodaypostsCnt}}</b>
                                    </td>
                                    <td>
                                        <span class="text-muted">今日主题</span><br>
                                        <b>{{.foruminfoxx.TodaythreadsCnt}}</b>
                                    </td>

                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
                <div class="form-group">
                    <div id="search_form">
                        <div class="input-group mb-3">
                            <input type="text" class="form-control" placeholder="关键词" name="keyword">
                            <div class="input-group-append">
                                <button class="btn btn-primary" type="button" id="searchbutton">搜索</button>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
</main>

<script>
    var jform = $('#search_form');
    var jsubmit = $('#searchbutton');

    jsubmit.on("click", function () {
        var jkeyword = jform.find('input[name="keyword"]').val();
        location.href = "/search.html?key=" + jkeyword
    })

    function pickTagThread(ele, forumid) {
        $(ele).addClass("tagactive").siblings().removeClass("tagactive")

        var tagarr = []
        $("#taglist").find(".tagactive").each(function () {
            var tagid = $(this).attr("tagid")
            if (tagid != 0) {
                tagarr.push(tagid)
            }
        })
        console.log(tagarr)
        var tagnum = tagarr.length
        console.log(tagnum)
        var tagstr = tagarr.join(",")

        if (tagnum != 0){

            var fd = new FormData()
            fd.append("tags", tagarr)
            $.ajax({
                url: "/api/v1/forum/"+ forumid +"/tagthread?tags="+tagstr,
                type: "GET",
                success: function (res) {
                    //成功
                    console.log(res)
                    // return
                    if (res.code == 200) {
                        $("#pagenation").remove()
                        $("#forumthreadlist").children().remove()
                        threads = res.data

                        var threadli = ""

                        for (var thread in threads) {
                            threadli += `<li class="media thread tap  " data-href="/thread/`+ threads[thread].ID +`/detail.html" data-tid="`+ threads[thread].ID +`">
                                    <a href=" /user/`+ threads[thread].user_id +`/info.html " tabindex="-1" class="ml-1 mt-1 mr-3">
                                        <img class="avatar-3" src="`+ threads[thread].user.avatar +`">
                                    </a>
                                    <div class="media-body">
                                        <div class="subject break-all font-weight-bold">
                                            <a href="/thread/`+ threads[thread].ID +`/detail.html">`+ threads[thread].subject +`</a>
                                         </div>
                                        <div class="d-flex justify-content-between small mt-1">
                                            <div>
                                                <span class="username text-grey mr-1 " uid="`+ threads[thread].user_id +`">`+ threads[thread].user.username +`</span>
                                                <span class="date text-grey">21天前</span>
                                            </div>
                                            <div class="text-muted small">
                                                <span class="ml-2"><i class="icon-eye"></i> `+ threads[thread].views_cnt +`</span>
                                                <span class="ml-2"><i class="icon-comment-o"></i>`+ threads[thread].posts_cnt +`</span>
                                            </div>
                                        </div>
                                    </div>
                                </li>`
                        }

                        $("#forumthreadlist").append(threadli)

                    } else {
                        $.alert(res.message)
                        return
                    }
                }
            })


        } else {
            location.reload()
        }
    }

</script>

{{ template "layout/footer" .}}
